package com.shirley.algorithm.sort;

import java.util.Arrays;

public class SelectSort extends SortBase {
    public static int[] sort(int[] source) {
        int[] arr = Arrays.copyOf(source, source.length);

        int minIndex = 0;
        for (int i = 0; i < arr.length - 1; i++) {
            minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[minIndex]) {
                    minIndex = j;
                }
            }
            swap(arr, i, minIndex);
        }
        return arr;
    }
}
